<?php
	if(!function_exists('redirect')){
		include ('../inc/config.php');
	} 
	if( isset($_GET['service']) ){	
		
		$url      = request('url','');
		$contador = request('contador',0);
		$service  = request('service','');
		$title    = request('title','');
		$description  = request('description','');
		
		$Shared['url']            = $url;
		$Shared[$service] = $contador+1;
		$ok = $db->Replace('shared', $Shared,'url', $autoquote = true); 
		
		if ($service=='twitter'){
			$redirect = "https://twitter.com/intent/tweet?text=$title vía @{$RedesSociales['twitter']['username']} $url";
		} elseif ($service=='facebook'){
			$redirect = "https://www.facebook.com/sharer/sharer.php?u=".urlencode($url);		
		} elseif ($service=='googleplus'){
			$redirect = "https://plus.google.com/share?url=".urlencode($url);		
		} elseif ($service=='linkedin'){
			$redirect = "http://www.linkedin.com/shareArticle?mini=true&url=$url&title=$title&summary=$description&source=$url";
		}
		redirect($redirect);
		die();

	} else {

		$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
		$shared_url = $url;
		$sql = "select * from shared where url='$shared_url'";
		$rs  = $db->SelectLimit($sql,1);
		$Shared = $rs->FetchRow();
		if(!$Shared){
			$Shared['url']        = $shared_url;
			$Shared['facebook']   = 0;
			$Shared['twitter']    = 0;
			$Shared['googleplus'] = 0;
			$Shared['linkedin']   = 0;
		}
		
		
		if (!empty($RedesSociales['twitter']['username'])) {
			$tw_username = '@'.$RedesSociales['twitter']['username'];
		} else {
			$tw_username = '';
		}
?>
		<script language="javascript">
		  function abrir(direccion, xancho, xalto){

			 var xancho = xancho;
			 var xalto = xalto;

			   var opciones = "fullscreen=" + 0 +
						   ",toolbar=" + 0 +
						   ",location=" + 0 +
						   ",status=" + 0 +
						   ",menubar=" + 0 +
						   ",scrollbars=" + 1 +
						   ",resizable=" + 0 +
						   ",width=" + xancho +
						   ",height=" + xalto +
						   ",left=" + (screen.availWidth-xancho)/2 +
						   ",top=" + (screen.availHeight-xalto)/2;
			   var ventana = window.open(direccion,"sharer",opciones);
		  }
		</script>

		<style>
		.a-share {text-decoration:right;}
		.share a:hover{text-align:right;}
		</style>
		
		<div class="share">
		
			<?php 
				//--------------------------- Facebook
				$ruta_facebook = "url=$url&contador={$Shared['facebook']}&service=facebook&title{$MetaTags['title']}&description{$MetaTags['description']}";
				
				//--------------------------- Twitter
				$ruta_twitter = "url=$url&contador={$Shared['twitter']}&service=twitter&title{$MetaTags['title']}&description{$MetaTags['description']}";

				//--------------------------- Google+
				$ruta_googleplus = "url=$url&contador={$Shared['googleplus']}&service=googleplus&title{$MetaTags['title']}&description{$MetaTags['description']}";				
				
				//-------------------------- LinkedIn
				$ruta_linkedin = "url=$url&contador={$Shared['linkedin']}&service=linkedin&title{$MetaTags['title']}&description{$MetaTags['description']}";				
				
			?>
			
			<table style='float:right;margin-bottom:5px;'>
				<tr>
					<td>
						<a href="#" title='Compartir en Facebook' onclick="javascript:abrir('<?php echo URL;?>/html/botones_compartir.html.php?<?php echo $ruta_facebook;?>',720,525);" class='a-share'>
						<img src='<?php echo URL;?>/img/icono-facebook.png'	
							style='cursor:pointer;' alt='Compartir en Facebook'>
						</a>
						<img src='<?php echo URL;?>/img/contador-left.png'	>
					</td>
					<td style="background:url(<?php echo URL;?>/img/contador-right.png) no-repeat center right;padding-right:8px;">
						<?php echo $Shared['facebook'];?>
					</td>
					<td style='padding-left:10px;'>
						<a href="#" title='Compartir en Twitter' onclick="javascript:abrir('<?php echo URL;?>/html/botones_compartir.html.php?<?php echo $ruta_twitter;?>',720,525);" class='a-share'>
						<img src='<?php echo URL;?>/img/icono-twitter.png'	
							style='cursor:pointer;' alt='Compartir en Twitter'>
						</a>
						<img src='<?php echo URL;?>/img/contador-left.png'	>
					</td>
					<td style="background:url(<?php echo URL;?>/img/contador-right.png) no-repeat center right;padding-right:8px;">
						<?php echo $Shared['twitter'];?>
					</td>
					<td style='padding-left:10px;'>
						<a href="#" title='Compartir en GooglePlus' onclick="javascript:abrir('<?php echo URL;?>/html/botones_compartir.html.php?<?php echo $ruta_googleplus;?>',720,525);" class='a-share'>
						<img src='<?php echo URL;?>/img/icono-google.png'	
							style='cursor:pointer;' alt='Compartir en GooglePlus'>
						</a>
						<img src='<?php echo URL;?>/img/contador-left.png'	>
					</td>
					<td style="background:url(<?php echo URL;?>/img/contador-right.png) no-repeat center right;padding-right:8px;">
						<?php echo $Shared['googleplus'];?>
					</td>
					<td style='padding-left:10px;'>
						<a href="#" title='Compartir en LinkedIn' onclick="javascript:abrir('<?php echo URL;?>/html/botones_compartir.html.php?<?php echo $ruta_linkedin;?>',720,525);" class='a-share'>
						<img src='<?php echo URL;?>/img/icono-linkedin.png'	
							style='cursor:pointer;' alt='Compartir en LinkedIn'>
						</a>
						<img src='<?php echo URL;?>/img/contador-left.png'	>
					</td>
					<td style="background:url(<?php echo URL;?>/img/contador-right.png) no-repeat center right;padding-right:8px;">
						<?php echo $Shared['linkedin'];?>
					</td>
					
				</tr>
			</table>
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-annotation="inline" data-width="300"></div>

<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
  window.___gcfg = {lang: 'es-419'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/platform.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>		

		</div>  
<?php } //endif ?>